package client;


import java.io.IOException;

public class ClientProxy {

    private ClientTransport transport;

    public ClientProxy(ClientTransport transport) {
        this.transport = transport;
    }

    public String send(String message) throws IOException, InterruptedException {
        transport.writeLine(message);
        return ClientResponseThread.getFromResponses();
    }

    public void sendMessage(String text) throws IOException, InterruptedException {
        transport.writeLine(text);
        String str = ClientResponseThread.getFromResponses();
        System.out.println(str);
    }

    public boolean sendPrivateMessage(String text) throws IOException, InterruptedException {
        transport.writeLine(text);
        switch (ClientResponseThread.getFromResponses()) {
            case "OK":
                return true;
            default:
                return false;
        }
    }

    public void getHistory(String cmd) throws IOException, InterruptedException {
        transport.writeLine(cmd);
        System.out.println (ClientResponseThread.getFromResponses());
    }

    public void setRoom(String name) throws IOException, InterruptedException {
        transport.writeLine(name);
        String str = ClientResponseThread.getFromResponses();
            System.out.println(str);
    }

    public void loggingOrReg(String cmd) throws IOException, InterruptedException {
        transport.writeLine(cmd);
        System.out.println (ClientResponseThread.getFromResponses());
    }
    /*
    public boolean changeNickname(String nickname) throws IOException, InterruptedException {
        transport.writeLine(nickname);
        switch (ClientResponseThread.getFromResponses()) {
            case "OK":
                return true;
            default:
                return false;
        }
    }
    */
    public ClientTransport getTransport() {
        return transport;
    }

    public void getRooms() throws IOException, InterruptedException {
        transport.writeLine("/rooms");
        System.out.println(ClientResponseThread.getFromResponses());
    }

}
